<?php

namespace app\http\middleware;

use app\nideshop\service\Token;

class CheckToken
{
    public function handle($request, \Closure $next)
    {
        if (empty($_SERVER['HTTP_X_NIDESHOP_TOKEN'])) {
            return json(['errno' => 401, 'errmsg' => '请登录', 'data' => []]);
        }
        if (!empty($_SERVER['HTTP_X_NIDESHOP_TOKEN'])) {
        	$userId = Token::unlock_url($_SERVER['HTTP_X_NIDESHOP_TOKEN']);
        	if ($userId <= 0) {
        		return json(['errno' => 401, 'errmsg' => '请登录', 'data' => []]);
        	}
        }
        return $next($request);
    }
}